import { _decorator, Component, Node, Sprite } from 'cc';
import { BaseComponent } from '../Manager/UIManager/BaseComponent';
import { GAME_POP, SOUND_TYPE } from '../Data/GlobalData';
const { ccclass, property } = _decorator;

@ccclass('PopStart')
export class PopStart extends BaseComponent {

    //判断是否是分享
    private IsShare: boolean = false;

    //分享提示
    @property(Node)
    private ShareTitle: Node = null;

    //广告提示
    @property(Node)
    private AdTitle: Node = null;

    //回调函数
    public Cb: Function = null;

    protected OnShow(): void {

        this.IsShare = Math.random() < 0.5;
        this.ShareTitle.active = false;
        this.AdTitle.active = false;

        if (this.IsShare) {
            this.ShareTitle.active = true;

        } else {
            this.AdTitle.active = true;
        }


    }

    /**
     * 点击确认
     */
    private ConfirmClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);

        if (this.IsShare) {
            app.adManager.ShareGame(() => {
                app.topManager.ShowPrompt("获取体力成功");
                this.Cb && this.Cb();
                app.popManager.HidePop(GAME_POP.PopStart);
            });
           

        } else {
            app.adManager.ShowVideo(0, (_isend: boolean) => {
                if (_isend) {
                    this.Cb && this.Cb();
                    app.popManager.HidePop(GAME_POP.PopStart);
                    app.topManager.ShowPrompt("获取体力成功");
                } else {
                    app.topManager.ShowPrompt("获取体力失败");
                }
            })
        }


    }

    /**
     * 返回点击
     */
    private CannelClick() {
        app.audioManager.PlayEffect(SOUND_TYPE.Button);
        app.popManager.HidePop(GAME_POP.PopStart);
    }




}


